
import React, {Component} from 'react';
import {Platform, StyleSheet, Text, View,Image,
  Dimensions,WebView,
} from 'react-native';
import TopBar from '../../bar/TopBar'
import BASEURL from '../../api/api'
import Loading from '../../common/Loading'
import Toast, {DURATION} from 'react-native-easy-toast'
var {height, width} = Dimensions.get('window');
export default class NoticeDetail extends Component {
  static navigationOptions = ({ navigation }) =>{
    return{
      headerTitle:<TopBar title='通知公告详情' navigation = {navigation}/>,
      headerLeft:null,//<LeftButton navigation = {navigation} />,
    }
  };
  constructor(props){
    super(props);
    this.state = ({
      notice:{},
      loading:true,
    })
    //console.log(this.props)
  }
  componentWillMount(){
    this.fetchData();
  }
  fetchData(){
    fetch(BASEURL+'getNotice?noticeId='+this.props.navigation.getParam('noticeId'))
    .then(res=>res.json())
    .then(response=>{
      //console.log('res',response)
      if(response.falg){
        this.setState({
          notice:response.notice,
          loading:false,
        })
      } else {
        this.setState({
          loading:false,
        })
        this.refs.toast.show('获取失败');
      }
      
    })
  }
  render(){
    var item = this.state.notice
    if(this.state.loading){
      return <Loading />
    } 
    return(
      <View style={styles.container}>
        <Text style={styles.title}>{item.notice_title}</Text>
        <View style={styles.rowView}>
          <Text style={styles.rowText}>{item.creator_id}</Text>
          <Text style={styles.rowText}>{item.create_time}</Text>
        </View>
        <WebView
          originWhitelist={['*']} 
          source={{ html: item.notice_content }}
          />
        <Toast ref="toast"/>
      </View>
    )
    
    
  }

}
const styles = StyleSheet.create({
  rowText:{
    fontSize:14,
    color:'#888',
    
  },
  rowView:{
    flexDirection:'row',
    justifyContent:'space-between',
    alignItems:'center',
    paddingTop:5,
    paddingBottom:10,
    borderBottomColor:'#aaa',
    borderBottomWidth:StyleSheet.hairlineWidth,
  },
  title:{
    fontSize:17,
    color:'#555',
  },
  container:{
    flex:1,
    padding:15,
  },

})